import { scrollMixin } from "utils/mixin";
import diyBackGround from "../balance/componet/diyBackGround.vue"

var currentTabIndex = "1";

export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      activeName: 'day',
      order_total_price:0,
      new_content:[],
      //加载更多
      isLoadMore: false,
      total_page: 0,
      page: 1,
    }
  },
  components:{
    diyBackGround
  },
  activated(){
    this.search()
  },
  methods: {
    getMoreData() {
      var that = this;
      this.isLoadMore = false;// 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        $http
          .get(
            "member.member-xj.fwzxstatics",
            {time_type:this.activeName, page: this.page },
            "正在获取更多订单"
          )
          .then(
            function (response) {
              if (response.result == 1) {
                that.isLoadMore = true;
                that.new_content = that.new_content.concat(response.data.list.data);
              } else {
                that.page = that.page - 1;
                that.isLoadMore = false;
                return;
              }
            },
            function (response) {
              // error callback
            }
          );
      }
    },
    handleClick() {
      // let name = this.activeName;
      // let index = '';
      // switch (name) {
      //   case "theDay":
      //     index = "1";
      //     break;
      //   case "theMonth":
      //     index = "2";
      //     break;
      //   case "lastMonth":
      //     index = "3";
      //     break;

      //   default:
      //     break;
      // }
      // //点击同tab 不刷新界面
      // if (currentTabIndex == index) {
      //   return;
      // } else {
      //   currentTabIndex = index;
      // }
      this.search();
    },
    search() {
      let that = this;
      this.isLoadMore = true;
      this.page = 1;
      this.total_page = 0;      
      let json = {
        'time_type':this.activeName,
        "page": this.page,
        "current_page":this.page,
      };
      $http.get('member.member-xj.fwzxstatics', json, "").then(function (response) {
        if (response.result === 1) {
          that.new_content = [];
          that.new_content = response.data.list.data;
          that.total_page = response.data.list.last_page;
          that.page = response.data.list.current_page;          
          that.order_total_price = response.data.totalyj;
        } else {
          console.log(response.msg);
        }
      }, function (response) {
        // error callback
      });
    },
  }
}